// pages/register/register.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id:"",
    password:"",
    passwordconfirm:"",
    sno:"",
    childNum:"",

  },
  idinput: function (event) {
    this.setData({ id: event.detail.value })
  },
  passwordinput: function (event) {
    this.setData({ password: event.detail.value })
  },
  passwordconfirminput: function (event) {
    this.setData({ passwordconfirm: event.detail.value })
  },
  snoinput: function (event) {
    this.setData({ sno: event.detail.value })
  },
  stunameinput: function (event) {
    this.setData({ childNum: event.detail.value })
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  },
  registerbtnClick:function(){
    var sha1 = require('../../utils/sha1')
    var md5 = require('../../utils/md5')

    var that=this;//请求的时候需要提交的参数
    var id = that.data.id;
    var psw = that.data.password;
    var mi_psw = md5.hex_md5(sha1.hex_sha1(psw));
    var sno = that.data.sno;
    var childNum = that.data.childNum;
    
    if (that.data.id == "" || that.data.password == "" || that.data.passwordconfirm == "" || that.data.sno == "" || that.data.childNum ==""){
      wx.showModal({
        title: "温馨提示",
        content: "信息填写不完整!"
      })
    } else if (that.data.passwordconfirm != that.data.password){
      wx.showModal({
        title: "温馨提示",
        content: "两次密码输入不一致!"
      })
    }else{
      wx.request({
        url: 'https://nottoday.club/index.php/api/Stuparent/parentRegister',
        data: {
          account: id,
          password: mi_psw,
          childName: sno,
          childNum: childNum,
        },
        method: "POST",
        dataType: "json",
        success: function (res) {
          wx.switchTab({
            url: '../my/my',
          })
          // console.log(childNum);
          // console.log("响应的数据" + res.data)
          // if (res.name == username) {
          // wx.showModal({
          // title: "信息提示",
          // content: "该用户名已被注册"
          // })
          // } else {
          // wx.showModal({
          // title: "信息提示",
          // content: "注册成功，请等待审核通过"
          // }),
          // wx.switchTab({
          // url: "../../myself/myself"
          // })
          // }
        },
        fail: function (res) {
          wx: wx.showToast({
            title: '服务器网络错误,请稍后重试',

            icon: 'loading',
            duration: 1500,
          })
        },
        complete: function (res) {

        }

      })
      
    }

    
  }
})